<!DOCTYPE html>
<html lang="{{ app()->getLocale() }}">
<head>
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <!-- CSRF Token -->
    <meta name="csrf-token" content="{{ csrf_token() }}">
    <title>{{ config('app.name', 'Laravel') }}</title>
    <!-- Styles -->
    @section('style')
        <link href="{{ asset('css/app.css') }}" rel="stylesheet">
        <link href="{{ asset('css/bootstrap.css') }}" rel="stylesheet">
        <style>
            body{
                position: relative;
                z-index: -1;
            }
            #app{
                position: relative;
                z-index: -1;
            }
        </style>
    @show
</head>
<body>
    <div id="app">
        <div class="alert alert-success" id="unread-msg">
            <a href="home" class="alert-link"></a>
        </div>
        <nav class="navbar navbar-default navbar-static-top">
            <div class="container">
                <div class="navbar-header">

                    <!-- Collapsed Hamburger -->
                    <button type="button" class="navbar-toggle collapsed" data-toggle="collapse" data-target="#app-navbar-collapse" aria-expanded="false">
                        <span class="sr-only">Toggle Navigation</span>
                        <span class="icon-bar"></span>
                        <span class="icon-bar"></span>
                        <span class="icon-bar"></span>
                    </button>

                    <!-- Branding Image -->
                    <a class="navbar-brand" href="{{ url('/') }}">
                        {{ config('app.name', 'Laravel') }}
                    </a>
                </div>

                <div class="collapse navbar-collapse" id="app-navbar-collapse">
                    <!-- Left Side Of Navbar -->
                    <ul class="nav navbar-nav navbar-left">
                        @guest
                            @else
                            <img style="height: 60px;width: 60px;border-radius: 50%" src="{{asset('uploads/'.Auth::user()->headpic)}}" alt="">
                        @endguest
                    </ul>
                    <!-- Right Side Of Navbar -->
                    <ul class="nav navbar-nav navbar-right">
                        <!-- Authentication Links -->
                        @guest
                            <li><a href="{{ route('login') }}">Login</a></li>
                            <li><a href="{{ route('register') }}">Register</a></li>
                        @else
                            <li class="dropdown">
                                <a href="#" class="dropdown-toggle" data-toggle="dropdown" role="button" aria-expanded="false" aria-haspopup="true">
                                    {{ Auth::user()->name }} <span class="caret"></span>
                                </a>

                                <ul class="dropdown-menu">
                                    <li>
                                        <a href="{{ url('home') }}">
                                            Home<span class="badge" style="background-color: #d9534f"></span>
                                        </a>
                                    </li>
                                    @can('view user')
                                    <li>
                                        <a href="{{ url('user') }}">
                                            User
                                        </a>
                                    </li>
                                    @endcan
                                    @can('view role')
                                    <li>
                                        <a href="{{ url('role') }}">
                                            Role
                                        </a>
                                    </li>
                                    @endcan
                                    @can('view permission')
                                    <li>
                                        <a href="{{ url('permission') }}">
                                            Permission
                                        </a>
                                    </li>
                                    @endcan
                                    @can('view log')
                                    <li>
                                        <a href="{{ url('log') }}">
                                            Log
                                        </a>
                                    </li>
                                    @endcan
                                    <li>
                                        <a href="{{ route('logout') }}"
                                           onclick="event.preventDefault();
                                                     document.getElementById('logout-form').submit();">
                                            Logout
                                        </a>
                                        <form id="logout-form" action="{{ route('logout') }}" method="POST" style="display: none;">
                                            {{ csrf_field() }}
                                        </form>
                                    </li>
                                </ul>
                            </li>
                        @endguest
                    </ul>
                </div>
            </div>
        </nav>
        @yield('content')
    </div>
    <!-- Scripts -->
    @section('script')
    {{--<script src="http://{{Request::getHost()}}:6001/socket.io/socket.io.js"></script>--}}
    <script src="{{ asset('js/all.js') }}"></script>
        <script>
            $.ajaxSetup({
                headers: {
                    'X-CSRF-TOKEN': $('meta[name="csrf-token"]').attr('content')
                }
            });
            let i=0;
            if(isNaN(parseInt(localStorage.num))){
                i=0;
            }else {
                i=parseInt(localStorage.num);
            }
            console.log(isNaN(parseInt(localStorage.num)));
            Echo.join(`chat.1`)
                .joining((user)=>{
                    $('#unread-msg a').html(user.name+' 上线了').parent().animate({
                        'top':'4px',
                    },300);
                    setTimeout(function(){
                        $('#unread-msg').animate({
                            'top':'-60px',
                        },300);
                    },6000);
                })
                .listen('Event', (e) => {
                    let headpic = e.user.headpic;
                    let txt = e.txt;
                    let time = '{{date('h:i')}}';
                    let name = e.user.name;
                    $('span.badge').html(++i);
                    localStorage.num=i;
                    $('#unread-msg a').html('<img style="height:26px;width:26px;border-radius:50%" src="{{asset('/uploads/')}}/'+headpic+'">  '+name+':'+txt).parent().animate({
                        'top':'4px',
                    },300);
                    setTimeout(function(){
                        $('#unread-msg').animate({
                            'top':'-60px',
                        },300);
                    },6000);
                });
            $(function () {
                $('span.badge').html(parseInt(localStorage.num));
            })
        </script>
    @show
</body>
</html>
